package com.beilang.hotline.issue.manager.impl;

import java.util.ArrayList;
import java.util.List;

import com.beilang.base.codelookup.manager.CodeLookupMgr;
import com.beilang.base.pagination.PaginationHelper;
import com.beilang.base.util.CodeConstant;
import com.beilang.hotline.issue.dao.IssueDAO;
import com.beilang.hotline.issue.manager.IssueMgr;
import com.beilang.hotline.issue.model.IssueModel;
import com.beilang.hotline.issue.to.SearchTO;

@SuppressWarnings("unchecked")
public class IssueMgrImpl implements IssueMgr{
	
	private IssueDAO issueDAO;
	
	private CodeLookupMgr codeLookupMgr;
	
	public void setCodeLookupMgr(CodeLookupMgr codeLookupMgr) {
		this.codeLookupMgr = codeLookupMgr;
	}

	public void setIssueDAO(IssueDAO issueDAO) {
		this.issueDAO = issueDAO;
	}
	
	public IssueModel createIssue(IssueModel issueModel){
		return issueDAO.createIssue(issueModel);
	} 
	
	public IssueModel saveIssue(IssueModel issueModel) {
		return issueDAO.saveIssue(issueModel);
	}
	
	public void deleteIssue(Long issueId){
		issueDAO.deleteIssue(issueId);
	}
	
	public IssueModel getIssue(Long issueId){
		IssueModel issueModel = issueDAO.getIssue(issueId);
        if (issueModel!=null)
        {
            issueModel.setSysName(codeLookupMgr.getCodeDesc(CodeConstant.SYS_NAME, issueModel.getSysId().toString()));
        }
        return issueModel;
	}
	
	public PaginationHelper getIssueList(PaginationHelper helper,SearchTO searchTO){
		int count = issueDAO.searchCount(searchTO);
		helper.setTotalSize(count);
		List list = issueDAO.searchList(helper, searchTO);
		if(list!=null&&list.size()>0){
			List l=new ArrayList();
            for (Object obj : list) {
                IssueModel issueModel = (IssueModel) obj;
                issueModel.setSysName(codeLookupMgr.getCodeDesc(CodeConstant.SYS_NAME, issueModel.getSysId().toString()));
                l.add(issueModel);
            }
			helper.setList(l);
		}else{
			helper.setList(list);
		}
		return helper;
	}

    public void deleteAllSysIssues(Long sysId){
         issueDAO.deleteAllSysIssues(sysId);
    }

}
